import { defineStore } from 'pinia'

const id = 'dialog'

const store = defineStore(id, {
  state: () => ({
    visible: false,
    title: '提示',
    content: '确定执行该操作？',
    actions: [] as Array<{
      type: '' | 'default' | 'text' | 'success' | 'warning' | 'info' | 'primary' | 'danger'
      label: string
    }>,
    action: ($index: number) => {}
  }),
  getters: {},
  actions: {
    open(
      title: string,
      content: string,
      actions: Array<{
        type: '' | 'default' | 'text' | 'success' | 'warning' | 'info' | 'primary' | 'danger'
        label: string
      }>,
      action: ($index: number) => void
    ) {
      this.title = title
      this.content = content
      this.actions = actions
      this.action = action
      this.visible = true
    },
    close() {
      this.$reset()
    }
  }
})

export default store
